package routes

import (
	"github.com/gin-gonic/gin"
	"group_-no.2/api"
	"group_-no.2/middleware"
	"group_-no.2/utils"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(middleware.Logger())
	r.Use(gin.Recovery())

	// 定义 router 变量
	auth := r.Group("api")
	//auth.Use(middleware.JwtToken())
	{
		// 用户模块的路由接口
		auth.PUT("user/:id", api.EditUser)
		auth.DELETE("user/:id", api.DeleteUser)
		// 分类模块的路由接口
		auth.POST("category/add", api.AddCate)
		auth.PUT("category/:id", api.EditCate)
		auth.DELETE("category/:id", api.DeleteCate)
		// 文章模块的路由接口
		auth.POST("article/add", api.AddArticle) //todo 任何用户都可以添加文章
		auth.PUT("article/:id", api.EditArticle)
		auth.DELETE("article/:id", api.DeleteArticle)
		//上传文件
		auth.POST("upload", api.Upload)
	}

	router := r.Group("api")
	{
		router.POST("user/add", api.AddUser)
		router.GET("users", api.GetUserList)
		router.GET("categories", api.GetCateList)
		router.POST("login", api.Login)
	}

	r.Run(":3000")
}
